package com.ming.DaoImp;

import com.ming.entity.user;
import com.ming.util.Database;
import com.ming.Dao.*;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/8/6 0006.
 */
public class userDaoImp extends Database implements userDao{
    public List<user> findUser(int id){
        List<user> list = new ArrayList<user>();
        Connection con = null;
        PreparedStatement stat = null;
        ResultSet rs = null;
        String sql = "SELECT  * from user where uid=?";
        equipmentDao eq = new equipmentDaoImp();
        try {
            con = Database.getConnection();
            stat = con.prepareStatement(sql);
            stat.setInt(1,id);
            rs = stat.executeQuery();
            while(rs.next()){
                user us = new user();
                us.setUid(rs.getInt("uid"));
                us.setUaddress(rs.getString("uaddress"));
                us.setUname(rs.getString("uname"));
                us.setUphone(rs.getString("uphone"));
                us.setUsex(rs.getString("usex"));
                us.setUemail(rs.getString("uemail"));
                list.add(us);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            Database.closeConnection(con,stat,rs);
        }
        return list;
    }
}
